﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MacomberMapSystem.Common.CIM;
using System.Drawing;

namespace MacomberMapSystem.Common.Exports
{
    /// <summary>
    /// This class holds a DDL exporter
    /// </summary>
    public class MM_DDL_Exporter_Stream: IDisposable
    {
        #region Variable Declarations
        /// <summary>The current indentation</summary>
        public int Indentation = 0;

        /// <summary>Our SCADA string writer</summary>
        public MM_DDL_Exporter_Target SCADA;


        /// <summary>Our NETMOM string writer</summary>
        public MM_DDL_Exporter_Target NETMOM;

        /// <summary>Our OTS string writer</summary>
        public MM_DDL_Exporter_Target OTS;

        /// <summary>Our collection of streams</summary>
        private MM_DDL_Exporter_Target[] Streams;
        #endregion

        #region Initialziation
        /// <summary>
        /// Initialize a new DDL exporter
        /// </summary>
        /// <param name="swOTS"></param>
        /// <param name="swNETMOM"></param>
        /// <param name="swSCADA"></param>
        public MM_DDL_Exporter_Stream(TextWriter swNETMOM, TextWriter swSCADA, TextWriter swOTS)
        {
            this.SCADA = new MM_DDL_Exporter_Target(swSCADA);
            this.NETMOM = new MM_DDL_Exporter_Target(swNETMOM);
            this.OTS = new MM_DDL_Exporter_Target(swOTS);
            this.Streams = new MM_DDL_Exporter_Target[] { SCADA, NETMOM, OTS };
        }

        #endregion

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="SymbolName"></param>
        /// <param name="Location"></param>  
        /// <param name="Cam"></param>
        /// <param name="Offset"></param>
        /// <param name="ToolTip"></param>
        public void WriteSymbolWithCamAndToolTip(string SymbolName, Point Location, Point Offset, String Cam, String ToolTip)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteSymbolWithCamAndToolTip(SymbolName, Location, Offset, Cam, ToolTip);
        }

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="SymbolName"></param>
        /// <param name="Location"></param>                
        /// <param name="ToolTip"></param>
        public void WriteSymbolWithToolTip(string SymbolName, Point Location, String ToolTip)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteSymbolWithToolTip(SymbolName, Location, ToolTip);
        }

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="SymbolName"></param>
        /// <param name="Location"></param>        
        /// <param name="Offset"></param>
        /// <param name="ToolTip"></param>
        public void WriteSymbolWithToolTip(string SymbolName, Point Location, Point Offset, String ToolTip)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteSymbolWithToolTip(SymbolName, Location, Offset, ToolTip);
        }

        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="Gab"></param>        
        /// <param name="Cam"></param>
        public void WriteRectangleWithCam(Rectangle Bounds, Point Offset, string Gab, String Cam)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRectangleWithCam(Bounds, Offset, Gab, Cam);
        }

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="LabelName"></param>
        /// <param name="ToolTip"></param>
        /// <param name="Location"></param>
        /// <param name="Keys"></param>
        public void WriteDataBoundPictureWithToolTip(string LabelName, string ToolTip, Point Location, params string[] Keys)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteDataBoundPictureWithToolTip(LabelName, ToolTip, Location, false,false, Keys);
        }
        
        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="LabelName"></param>
        /// <param name="ToolTip"></param>
        /// <param name="Location"></param>
        /// <param name="Keys"></param>
        public void WriteDataBoundPictureWithToolTip(string LabelName, string ToolTip, Point Location, string[] Keys, bool XLocked, bool YLocked)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteDataBoundPictureWithToolTip(LabelName, ToolTip, Location, XLocked, YLocked, Keys);
        }

        /// <summary>
        /// Write out the DDL header
        /// </summary>
        /// <param name="VersionInfo"></param>
        public void WriteHeader(String VersionInfo)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteHeader(VersionInfo);
        }

        /// <summary>
        /// Write an attribute out to the DDL export
        /// </summary>
        /// <param name="Name">The name of the attribute</param>        
        public void WriteAttribute(String Name)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteAttribute(Name);
        }
        /// <summary>
        /// Write an attribute out to the DDL export
        /// </summary>
        /// <param name="Name">The name of the attribute</param>
        /// <param name="Value">The value of the attribute</param>
        public void WriteAttribute(String Name, float Value)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteAttribute(Name, Value);
        }

        /// <summary>
        /// Write an attribute out to the DDL export
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Value"></param>
        public void WriteAttribute(String Name, String Value)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteAttribute(Name, Value);
        }

        /// <summary>
        /// Write an attribute out to the DDL export
        /// </summary>
        /// <param name="Name">The name of the attribute</param>
        /// <param name="Value1">The value of the attribute</param>
        /// <param name="Value2">The second value of the attribute</param>
        public void WriteAttribute(String Name, float Value1, float Value2)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteAttribute(Name, Value1, Value2);
        }

        /// <summary>
        /// Write an attribute out to the DDL export
        /// </summary>
        /// <param name="Name1">The name of the attribute</param>
        /// <param name="Name2">The second name of the attribute</param>
        /// <param name="Value">The value of the attribute</param>
        public void WriteAttribute(String Name1, String Name2, String Value)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteAttribute(Name1, Name2, Value);
        }

        /// <summary>
        /// Write the starting tag of component
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Value"></param>
        public void WriteStartTag(string Name, string Value)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteStartTag(Name, Value);
        }


        /// <summary>
        /// Write the end of a tag
        /// </summary>
        public void WriteEndTag()
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteEndTag();
        }

        /// <summary>
        /// Write a rotated attribute
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="Height"></param>
        /// <param name="Width"></param>
        /// <param name="Angle"></param>
        public void WriteRotatedAttribute(string Name, int X, int Y, int Width, int Height, int Angle)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRotatedAttribute(Name, X, Y, Width, Height, Angle);
        }

        /// <summary>
        /// Write a single line, and if requested, an arrow on the receiving end
        /// </summary>
        /// <param name="Pt1">The start point</param>
        /// <param name="Pt2">The end point</param>
        /// <param name="ToArrow">Whether an arrow would be drawn</param>
        /// <param name="Gab">The name of the gab</param>
        public void WriteGraphicLine(Point Pt1, Point Pt2, bool ToArrow, string Gab)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteGraphicLine(Pt1, Pt2, ToArrow, Gab);
        }

        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="ForeColor"></param>
        /// <param name="Comment"></param>
        public void WriteFilledRectangleWithComment(Rectangle Bounds, Point Offset, string ForeColor, string Comment)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteFilledRectangleWithComment(Bounds, Offset, ForeColor, Comment);
        }

        /// <summary>
        /// Write a text box
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Cam"></param>
        /// <param name="Location"></param>
        /// <param name="Foreground"></param>
        /// <param name="Background"></param>
        /// <param name="Font"></param>
        /// <param name="FontSize"></param>
        /// <param name="Underline"></param>
        /// <param name="Bold"></param>
        /// <param name="Italics"></param>
        /// <param name="xLocked"></param>
        /// <param name="yLocked"></param>
        public void WriteTextWithCam(String Text, String Cam, Point Location, String Foreground, String Background, String Font, int FontSize, bool Underline, bool Bold, bool Italics, bool xLocked, bool yLocked)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteTextWithCam(Text, Cam, Location, Foreground, Background, Font, FontSize, Underline, Bold, Italics, xLocked, yLocked);
        }

        /// <summary>
        /// Write a text box
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Location"></param>
        /// <param name="Foreground"></param>
        /// <param name="Background"></param>
        /// <param name="Font"></param>
        /// <param name="FontSize"></param>
        /// <param name="Underline"></param>
        /// <param name="Bold"></param>
        /// <param name="Italics"></param>
        /// <param name="xLocked"></param>
        /// <param name="yLocked"></param>
        public void WriteText(String Text, Point Location, String Foreground, String Background, String Font, int FontSize, bool Underline, bool Bold, bool Italics, bool xLocked, bool yLocked)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteText(Text, Location, Foreground, Background, Font, FontSize, Underline, Bold, Italics, xLocked, yLocked);
        }

        /// <summary>
        /// Close our string writer parentheses
        /// </summary>
        public void Close()
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.Close();
        }


        /// <summary>
        /// Write out an ellipse with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="BackColor"></param>
        /// <param name="ForeColor"></param>
        public void WriteEllipse(Rectangle Bounds, Point Offset, string ForeColor, string BackColor)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteEllipse(Bounds, Offset, ForeColor, BackColor);
        }

        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="BackColor"></param>
        /// <param name="ForeColor"></param>
        public void WriteRectangle(Rectangle Bounds, Point Offset, string ForeColor, string BackColor, bool XLocked = false, bool YLocked = false)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRectangle(Bounds, Offset, ForeColor, BackColor, XLocked, YLocked);
        }


        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="Gab"></param>
        public void WriteRectangle(Rectangle Bounds, Point Offset, string Gab)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRectangle(Bounds, Offset, Gab);
        }

        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="Gab"></param>        
        /// <param name="Cam"></param>
        /// <param name="Keyset"></param>
        /// <param name="ToolTip"></param>
        public void WriteRectangleWithCamAndKeysetAndToolTip(Rectangle Bounds, Point Offset, string Gab, String Cam, string Keyset, String ToolTip)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRectangleWithCamAndKeysetAndToolTip(Bounds, Offset, Gab, Cam, Keyset, ToolTip);
        }


        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="SymbolName"></param>
        /// <param name="Location"></param>  
        /// <param name="Cam"></param>
        /// <param name="Offset"></param>
        public void WriteSymbolWithCam(string SymbolName, Point Location, Point Offset, String Cam)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteSymbolWithCam(SymbolName, Location, Offset, Cam);
        }

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="SymbolName"></param>
        /// <param name="Location"></param>        
        public void WriteSymbol(string SymbolName, Point Location)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteSymbol(SymbolName, Location);
        }

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="SymbolName"></param>
        /// <param name="Location"></param>  
        /// <param name="Offset"></param>
        public void WriteSymbol(string SymbolName, Point Location, Point Offset)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteSymbol(SymbolName, Location, Offset);
        }

        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="Gab"></param>        
        /// <param name="Cam"></param>
        /// <param name="Keyset"></param>
        public void WriteRectangleWithCamAndKeyset(Rectangle Bounds, Point Offset, string Gab, String Cam, string Keyset)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRectangleWithCamAndKeyset(Bounds, Offset, Gab, Cam, Keyset);
        }

        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="Gab"></param>
        /// <param name="Keyset"></param>
        public void WriteRectangleWithKeyset(Rectangle Bounds, Point Offset, string Gab, string Keyset)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRectangleWithKeyset(Bounds, Offset, Gab, Keyset);
        }

        /// <summary>
        /// Write out a rectangle with specified gab
        /// </summary>
        /// <param name="Bounds"></param>
        /// <param name="Offset"></param>
        /// <param name="Gab"></param>
        /// <param name="Keyset"></param>
        /// <param name="ToolTip"></param>
        public void WriteRectangleWithKeysetAndToolTip(Rectangle Bounds, Point Offset, string Gab, string Keyset, String ToolTip)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteRectangleWithKeysetAndToolTip(Bounds, Offset, Gab, Keyset, ToolTip);
        }
        /// <summary>
        /// Write a blank line
        /// </summary>
        public void WriteLine()
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteLine();
        }

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="LabelName"></param>
        /// <param name="Location"></param>
        /// <param name="Keys"></param>
        public void WriteDataBoundPicture(string LabelName, Point Location, params string[] Keys)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteDataBoundPicture(LabelName, Location, Keys);
        }

        /// <summary>
        /// Write text using an existing gab
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Gab"></param>
        /// <param name="Location"></param>
        /// <param name="xlocked"></param>
        /// <param name="ylocked"></param>
        public void WriteTextWithGab(String Text, String Gab, Point Location, bool xlocked, bool ylocked)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteTextWithGab(Text, Gab, Location, xlocked, ylocked);
        }

        /// <summary>
        /// Write text using an existing gab
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Gab"></param>
        /// <param name="Location"></param>
        /// <param name="xlocked"></param>
        /// <param name="ylocked"></param>
        public void WriteTextWithGabAndToolTip(String Text, String Gab, Point Location, String ToolTip, bool xlocked, bool ylocked)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams)
                Target.WriteTextWithGabAndToolTip(Text, Gab, Location, ToolTip,  xlocked, ylocked);
        }

        /// <summary>
        /// Write text using an existing gab
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Gab"></param>
        /// <param name="Location"></param>
        /// <param name="xlocked"></param>
        /// <param name="ylocked"></param>
        public void WriteTextWithGabAndToolTipAndKeySet(String Text, String Gab, Point Location, String ToolTip, bool xlocked, bool ylocked, String KeySet)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams)
                Target.WriteTextWithGabAndToolTipAndKeySet(Text, Gab, Location, ToolTip, xlocked, ylocked, KeySet);
        }

        /// <summary>
        /// Write out an old-style picture with associated records
        /// </summary>
        /// <param name="SymbolName"></param>
        /// <param name="Location"></param>        
        /// <param name="Keyset"></param>
        public void WriteSymbolWithKeyset(string SymbolName, Point Location, String Keyset)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteSymbolWithKeyset(SymbolName, Location, Keyset);
        }

        /// <summary>
        /// Write text using an existing gab
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Gab"></param>
        /// <param name="Location"></param>
        /// <param name="xlocked"></param>
        /// <param name="ylocked"></param>
        /// <param name="Cam"></param>
        public void WriteTextWithCamAndGab(String Text, String Cam, String Gab, Point Location, bool xlocked, bool ylocked)
        {
            foreach (MM_DDL_Exporter_Target Target in Streams) 
                    Target.WriteTextWithCamAndGab(Text, Cam, Gab, Location, xlocked, ylocked);
        }

        /// <summary>
        /// Handle disposal
        /// </summary>
        public void Dispose()
        {
            foreach (MM_DDL_Exporter_Target Target in Streams)
                Target.Dispose();
        }
    }
}